package cn.zjutleo.village_server.service;

import cn.zjutleo.village_server.entity.CooperateParticipant;
import cn.zjutleo.village_server.exception.apiException.daoException.SelectException;
import cn.zjutleo.village_server.exception.apiException.daoException.UpdateException;
import cn.zjutleo.village_server.mapper.CooperateMapper;
import cn.zjutleo.village_server.mapper.CooperateParticipantMapper;
import cn.zjutleo.village_server.vo.CooperateVo;

import javax.annotation.Resource;

/**
 * @Author ：杜雨茜
 * @Description ：村民互助活动报名
 * @Date ：2021/12/22 23:39
 **/
public class CooperateParticipantService {
    @Resource
    CooperateParticipantMapper cooperateParticipantMapper;
    /**
     * Description 保存
     **/
    public void saveParticipant(CooperateParticipant cooperateParticipant) {
        cooperateParticipantMapper.insertSelective(cooperateParticipant);
    }

    /**
     * Description 删除
     **/
    public void deleteParticipantById(Integer id) {
        cooperateParticipantMapper.deleteByPrimaryKey(id);
    }

    /**
     * Description 根据id查找活动参与者，找不到则返回报错
     **/
    public CooperateParticipant getExistParticipantById(Integer id){
        CooperateParticipant participant = cooperateParticipantMapper.selectByPrimaryKey(id);
        if(participant == null){
            try {
                throw new SelectException("参与者不存在！");
            } catch (SelectException e) {
                e.printStackTrace();
            }
        }
        return participant;
    }
    /**
     * Description 修改参与者的姓名或电话
     **/
    public void updateParticipantById(CooperateParticipant cooperateParticipant){
        int i= cooperateParticipantMapper.updateByPrimaryKey(cooperateParticipant);
        if(i == 0)
        {
            try {
                throw new UpdateException("更新失败！");
            } catch (UpdateException e) {
                e.printStackTrace();
            }
        }
    }
}
